<?php $this->headLink()->prependStylesheet(Ac_Util::getImageBaseUrl('/css/custom_ad_detail.v-'.AC_VERSION.'.css'))?>
<?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/custom_acc.v-'.AC_VERSION.'.css'))?>
<?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/custom_serp.v-'.AC_VERSION.'.css'))?>
<?php $this->JQuery()->javascriptCaptureStart()?>
$j(document).ready(function() {

    $j('#form_list_head select').change(function () {
        $j('#form_list_head').submit();
    });
    /*$j('#select_all1').click(function() {
        $j('.chk_select').attr('checked', true);
    });
    $j('#select_none1').click(function() {
        $j('.chk_select').attr('checked',false);
    });
    $j('#select_all2').click(function() {
        $j('.chk_select').attr('checked', true);
    });
    $j('#select_none2').click(function() {
        $j('.chk_select').attr('checked',false);
    });*/
    
    $j('#head_ckeckbox').click(function(){
		if(this.checked){
			//alert('checked!');
			$j('.chk_select').attr('checked', true);
		}else{
			//alert('unchecked!');
			$j('.chk_select').attr('checked', false);
		}
	});

    $j('#search_text').change(function() {
        $j('#search_text2').attr('value',$j('#search_text').attr('value'));
    });

    $j('#search_text2').change(function() {
        $j('#search_text').attr('value',$j('#search_text2').attr('value'));
    });

    //Select Action
    $j('.select_action_ads').change(function() {
        if (($(this).attr('name') == 'action1') || ($(this).attr('name') == 'action2')) {
            if ($(this).attr('name') == 'action1') {
                $j('#select_action2').attr('value',$(this).attr('value'));
            }
            if ($(this).attr('name') == 'action2') {
                $j('#select_action1').attr('value',$(this).attr('value'));
            }
            return false;
        }
    });


    $j('#form_chk_select').find('select').change(function() {
        var $message;
        var checked = $j("input:checked").length;

        //Actions for Sort By Selects
        if ($(this).attr('id') == 'sort1') {
            $j('#sort2').attr('value', $(this).attr('value'));
            $j('#form_chk_select').submit();
        }
        if ($(this).attr('id') == 'sort2') {
            $j('#sort1').attr('value', $(this).attr('value'));
            $j('#form_chk_select').submit();
        }

        //Actions for Upper selects
        if (($(this).attr('value') == 'renew') ||
            ($(this).attr('value') == 'unpublish') ||
            ($(this).attr('value') == 'publish') ||
            ($(this).attr('value') == 'markassold') ||
            ($(this).attr('value') == 'markasunsold') ||
            ($(this).attr('value') == 'delete'))
        {
            if (checked != 0) {
                if ($(this).attr('value') == 'renew') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to renew your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定你想更新这个广告吗？')?>";
                    }
                }
                if ($(this).attr('value') == 'unpublish') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to unpublish your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定要取消发布此广告吗？')?>";
                    }
                }
                if ($(this).attr('value') == 'publish') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to publish your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定你要发布这个广告吗？')?>";
                    }
                }
                if ($(this).attr('value') == 'markassold') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ads as Sold ?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定您的广告要标记为售出吗？')?>";
                    }
                }
                if ($(this).attr('value') == 'markasunsold') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ads as Unsold ?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定您的广告要标记为未售出吗？')?>";
                    }
                }
                if ($(this).attr('value') == 'delete') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to delete your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('确定要删除此广告吗？')?>";
                    }
                }

                if (confirm($message)) {
                    $j('#form_chk_select').submit();
                }
                else {
                    $(this).attr('value','');
                    return false;
                }
            }
            else {
                $(this).attr('value','');
                alert('<?php echo $this->t('请至少选择一个广告')?>');
            }
        }
        else {
            if (($(this).attr('name') == 'search_type') || ($(this).attr('name') == 'search_type2')) {
                if ($(this).attr('name') == 'search_type') {
                    $j('#search_type2').attr('value',$(this).attr('value'));
                }
                if ($(this).attr('name') == 'search_type2') {
                    $j('#search_type').attr('value',$(this).attr('value'));
                }
                return false;
            }
            else {
                $j('#form_chk_select').submit();
            }
        }

    });

    <?php if (isset($_GET['ac'])) { ?>
        $j('#update_message').show().delay(4000).fadeOut();
    <?php } ?>

    <?php if (!empty($_POST['action1'])) { ?>
        $j('#update_message').show().delay(4000).fadeOut();
    <?php } ?>


    // Renew Action Simple
    $j('.renew_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to renew this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Publish Action Simple
    $j('.publish_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to publish this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Unpublish Action Simple
    $j('.unpublish_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to unpublish this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Delete Action Simple
    $j('.delete_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to delete this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });


    // Mark as sold Action Simple
    $j('.markassold_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to mark your Ad as sold?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Mark as sold Action Simple
    $j('.markasunsold_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to mark your Ad as unsold?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php $this->placeholder('container-class')->set('acc ads')?>
<?php
$get = $_GET;
$tab = !empty($get['tab']) ? $get['tab'] : Model_Listing::STATUS_PUBLISHED;
$url = $this->geturl('my-account-ads', 'user', null, array(), $get);
$separator = (strpos($url, '?') !== false) ? '&' : '?';
$get['category'] = empty($get['category']) ? '' : $get['category'];
?>
<article class="article box">
  <?php echo $this->partial('index/my-account-side.phtml', array('select'=> 'my-ad')) ?>
    <section class="main_section">
	    <h3><?php echo $this->t('信息总汇')?></h3>
	    <p class="alert" style="display:none;" id="update_message">
        <?php

        if (isset($_POST['action1'])) {
            if (isset($_POST['chk'])) {
                $size = count($_POST['chk']);
                if ($size > 1) {
                    $msg = $size.$this->t(' Ads have');
                }
                else {
                    $msg = $this->t('Your Ad has');
                }
            }
            if ($_POST['action1'] == 'publish') {
                echo $msg.$this->t(' been published and moved to your Published Ads folder');
            }
            if ($_POST['action1'] == 'unpublish') {
                echo $msg.$this->t(' been unpublished and moved to your Draft Ads folder');
            }
            if ($_POST['action1'] == 'delete') {
                echo $msg.$this->t(' been deleted');
            }
            if ($_POST['action1'] == 'renew') {
                echo $msg.$this->t(' been renewed');
            }
            if ($_POST['action1'] == 'markassold') {
                echo $msg.$this->t(' been marked as sold');
            }
            if ($_POST['action1'] == 'markasunsold') {
                echo $msg.$this->t(' been marked as unsold');
            }
        }

        if (isset($_GET['ac'])) {
            if (isset($_GET['nb'])) {
                if ($_GET['nb'] > 1) {
                    $msg = $_GET['nb'].$this->t(' Ads have');
                }
                else {
                    $msg = $this->t('Your Ad has');
                }
            }
            if ($_GET['ac'] == 'publish') {
                echo $msg.$this->t(' been published and moved to your Published Ads folder');
            }
            if ($_GET['ac'] == 'unpublish') {
                echo $msg.$this->t(' been unpublished and moved to your Draft Ads folder');
            }
            if ($_GET['ac'] == 'delete') {
                echo $msg.$this->t(' been deleted');
            }
            if ($_GET['ac'] == 'markassold') {
                echo $msg.$this->t(' been marked as sold');
            }
            if ($_GET['ac'] == 'markasunsold') {
                echo $msg.$this->t(' been marked as unsold');
            }
            if ($_GET['ac'] == 'renew') {
                echo $msg.$this->t(' been renewed');
            }
            //if ($_GET['ac'] == 'markassold') {
                //echo $msg.' been marked as Sold';
            //}
        } ?>
    	</p>
		<section class="result list">
		<form action="<?php echo $this->geturl('my-account-ads', 'user')?>" method="POST" id="form_chk_select" name="form_chk_select">
	        <section class="business_personal"> 
				<a href="<?php echo $this->geturl('my-account-ads', 'user', null, array(), array('tab' => Model_Listing::STATUS_PUBLISHED))?>" <?php echo ($tab == 1) ? 'class="selected"' : ''; ?> ><em><?php echo $this->t('已发布信息')?></em> (<?php echo number_format((int) $this->loggedin_user->getPublishedAds()->count())?>)</a> 
				<a href="<?php echo $this->geturl('my-account-ads', 'user', null, array(), array('tab' => Model_Listing::STATUS_DRAFT))?>" <?php echo ($tab != 1) ? 'class="selected"' : ''; ?> ><em><?php echo $this->t('信息草稿')?></em> (<?php echo number_format($this->tabs[Model_Listing::STATUS_DRAFT])?>)</a>
			</section>
			<input type="hidden" value="<?php echo empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']?>" name="tab">
            <section class="list_head">
            	<dl class="checkbox select">
					<dt><input type="checkbox" id="head_ckeckbox"></dt>
				</dl>
				<dl class="product">
					<dt><?php echo $this->t('宝贝')?></dt>
				</dl>
                <dl class="category" id="select_category">
                    <dt>
                        <select name="category">
                            <option value=""><?php echo $this->t('类别')?></option>
                            <?php $list = array_keys((array)$this->list_filter->category_attached);?>

                            <?php foreach($list as $k => $cat):?>
                                <?php

                                    $category = Model_Category::find($cat);
                                    if (!empty($category)) {
                                        $name = '';
                                        $to_add = '';
                                        $selected = $_REQUEST['category'] == (string) $category->_id ? ' selected' : '';
                                        foreach($category->getParentTree() as $ele) {
                                            $name.= $to_add.$ele->name;
                                            $to_add = ' > ';
                                        }
                                        ?>
                                        <option value="<?php echo $cat?>" <?php echo $selected?>><?php echo $name?></option>
                                        <?php
                                    }
                                ?>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="location">
                    <dt>
                        <select name="location">
                            <option value=""><?php echo $this->t('地址')?></option>
                            <?php foreach((array)$this->list_filter->area_l2 as $k => $cat):?>
                                <?php
                                    $location = Model_Location::find($k);
                                    $name   = '';
                                    $to_add = '';
                                    $name   = $location->name;
                                    $selected = (empty($_REQUEST['location']) && $_REQUEST['location'] == (string) $k) ? ' selected' : '';
                                ?>
                                <option value="<?php echo $k?>" <?php echo $selected?>><?php echo $name?></option>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="post_date">
                    <dt>
                        <select name="post_date">
                            <option value=""><?php echo $this->t('发布日期')?></option>
                            <?php foreach($this->list_filter_date as $k => $cat):?>
                                <?php
                                    $selected = (!empty($_REQUEST['post_date']) && $_REQUEST['post_date'] == (string) $k) ? ' selected' : '';
                                ?>
                                <option value="<?php echo $k?>" <?php echo $selected?>><?php echo $cat?></option>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="view">
                    <dt><?php echo $this->t('Views')?></dt>
                </dl>
            </section>
			<?php if(($this->loggedin_user->getPublishedAds()->count() > 0 && $tab == Model_Listing::STATUS_PUBLISHED) || ($this->tabs[Model_Listing::STATUS_DRAFT] > 0 && $tab == Model_Listing::STATUS_DRAFT)): ?>
			<ul id="list">
				<?php
				    $display_photo = true;
				    $display_user  = false;
				    $replace_like_with_follow = false;
				    $display_price = true;
				    $display_customization = false;
				    $display_view = true;
				    $display_modify = true;
				    $display_checkbox = true;
				    if (!empty($_GET['small_category_list'])) {
				        $cat = Model_Category::find($_GET['small_category_list']);
				        if ($cat->customization == 'job') {
				            $display_photo = false;
				            $display_user  = false;
				            $class = '';
							$display_customization = false;
				        } elseif ($cat->id == 'mc52') { //business directory
				            $display_photo = false;
				            $display_user  = false;
				            $class = '';
				            $replace_like_with_follow = true;
				            $display_price = false;
				            $display_customization = true;
				        }
				    }
				?>	
				<?php  foreach ($this->list as $listing):?>
				<?php 
				    if ($listing->type_obj == Model_Company::TYPE) {
				        $item = Model_Company::find($listing->id);
				    } else {
				        $item = Model_Listing::find($listing->id);
				    }
				?>
				<?php if(empty($item)){ continue;}?>
					<li class="item">
					    <?php
					        $this->partial()->setObjectKey('model');
					        echo $this->partial(
					            'index/listing-element.phtml',
					            'search',
					            array(
					                'item'                        => $item,
					                'photo_width'                 => 60,
					                'photo_height'                => 60,
					                'photo_params'                => array(),
					                'display_photo'               => $display_photo,
					                'display_user'                => $display_user,
					                'display_photo_if_not_exists' => true,
					                'display_category'            => true,
					                'display_customization'       => $display_customization,
					                'display_date'                => false,
					                'display_price'               => $display_price,
					                'replace_like_with_follow'    => $replace_like_with_follow,
					                'display_view'				  => $display_view,
					                'display_checkbox'			  => $display_checkbox,
					                'display_modify'			  => $display_modify,
					                'display_function'			  => false,
					        ));
					    ?>
					</li>
				<?php endforeach; ?>
			</ul>
			<?php else: ?>
			<p class="no_ad button em"><?php echo $this->t('噢，你还没有分享过任何宝贝哩，不妨尝试<a href="'.$this->geturl('post-an-ad', 'listing').'">发新讯息</a>吧！')?></p>
			<?php endif; ?>
			
			<section class="search">
				<form>
					<input type="text" name="search_text" id="search_text" value="<?php echo empty($_REQUEST['search_text']) ? '' : $_REQUEST['search_text']?>">
					<button>Search</button>
				</form>
			</section>
			
	        <section class="nav option top">
				<dl class="sort">
                    <dt><?php echo $this->t('排列')?></dt>
                    <dd>
                        <?php foreach($this->sort_by as $k => $value):?>
                            <?php $url1 = preg_replace('#&sort=[^&]*#', '', $url);?>
                            <a href="<?php echo $url1.$separator.'sort='.$k?>" class="<?php echo $this->sort == $k ? 'selected': ''?>"><?php echo $value;?></a>
                        <?php endforeach;?>
                    </dd>
                </dl>
				<?php if(!empty($this->list)):?>
					<?php
                    $get = $_REQUEST;
                    unset($get['page']);
                    $pagination = $this->pagination($this->listing_number, $this->page, $this->per_page, 4, $this->geturl('my-account-ads', 'user', null, null, $get), '&page=');
                    echo $pagination;
                	?>
                <?php endif;?>
	        </section>
			<section class="nav option bottom">
				<dl class="sort">
                    <dt><?php echo $this->t('排列')?></dt>
                    <dd>
                        <?php foreach($this->sort_by as $k => $value):?>
                            <?php $url1 = preg_replace('#&sort=[^&]*#', '', $url);?>
                            <a href="<?php echo $url1.$separator.'sort='.$k?>" class="<?php echo $this->sort == $k ? 'selected': ''?>"><?php echo $value;?></a>
                        <?php endforeach;?>
                    </dd>
                </dl>
            	<?php if(!empty($this->list)):?>
					<?php
                    $get = $_REQUEST;
                    unset($get['page']);
                    $pagination = $this->pagination($this->listing_number, $this->page, $this->per_page, 4, $this->geturl('my-account-ads', 'user', null, null, $get), '&page=');
                    echo $pagination;
                	?>
                <?php endif;?>
			</section>
		</form>
	    </section>
	    
	</section>
    <aside class="aside">
    </aside>
</article>

<?php /* $this->JQuery()->javascriptCaptureStart()?>
$j(document).ready(function() {

    $j('#form_list_head select').change(function () {
        $j('#form_list_head').submit();
    });
    $j('#select_all1').click(function() {
        $j('.chk_select').attr('checked', true);
    });
    $j('#select_none1').click(function() {
        $j('.chk_select').attr('checked',false);
    });
    $j('#select_all2').click(function() {
        $j('.chk_select').attr('checked', true);
    });
    $j('#select_none2').click(function() {
        $j('.chk_select').attr('checked',false);
    });

    $j('#search_text').change(function() {
        $j('#search_text2').attr('value',$j('#search_text').attr('value'));
    });

    $j('#search_text2').change(function() {
        $j('#search_text').attr('value',$j('#search_text2').attr('value'));
    });

    //Select Action
    $j('.select_action_ads').change(function() {
        if (($(this).attr('name') == 'action1') || ($(this).attr('name') == 'action2')) {
            if ($(this).attr('name') == 'action1') {
                $j('#select_action2').attr('value',$(this).attr('value'));
            }
            if ($(this).attr('name') == 'action2') {
                $j('#select_action1').attr('value',$(this).attr('value'));
            }
            return false;
        }
    });


    $j('#form_chk_select').find('select').change(function() {
        var $message;
        var checked = $j("input:checked").length;

        //Actions for Sort By Selects
        if ($(this).attr('id') == 'sort1') {
            $j('#sort2').attr('value', $(this).attr('value'));
            $j('#form_chk_select').submit();
        }
        if ($(this).attr('id') == 'sort2') {
            $j('#sort1').attr('value', $(this).attr('value'));
            $j('#form_chk_select').submit();
        }

        //Actions for Upper selects
        if (($(this).attr('value') == 'renew') ||
            ($(this).attr('value') == 'unpublish') ||
            ($(this).attr('value') == 'publish') ||
            ($(this).attr('value') == 'markassold') ||
            ($(this).attr('value') == 'markasunsold') ||
            ($(this).attr('value') == 'delete'))
        {
            if (checked != 0) {
                if ($(this).attr('value') == 'renew') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to renew your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to renew your Ad?')?>";
                    }
                }
                if ($(this).attr('value') == 'unpublish') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to unpublish your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to unpublish your Ad?')?>";
                    }
                }
                if ($(this).attr('value') == 'publish') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to publish your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to publish your Ad?')?>";
                    }
                }
                if ($(this).attr('value') == 'markassold') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ads as Sold ?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ad as Sold ?')?>";
                    }
                }
                if ($(this).attr('value') == 'markasunsold') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ads as Unsold ?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to mark your Ad as Unsold ?')?>";
                    }
                }
                if ($(this).attr('value') == 'delete') {
                    if (checked > 1) {
                        $message = "<?php echo $this->t('Are you sure you want to delete your Ads?')?>";
                    } else {
                        $message = "<?php echo $this->t('Are you sure you want to delete your Ad?')?>";
                    }
                }

                if (confirm($message)) {
                    $j('#form_chk_select').submit();
                }
                else {
                    $(this).attr('value','');
                    return false;
                }
            }
            else {
                $(this).attr('value','');
                alert('<?php echo $this->t('Please check at least one Ad.')?>');
            }
        }
        else {
            if (($(this).attr('name') == 'search_type') || ($(this).attr('name') == 'search_type2')) {
                if ($(this).attr('name') == 'search_type') {
                    $j('#search_type2').attr('value',$(this).attr('value'));
                }
                if ($(this).attr('name') == 'search_type2') {
                    $j('#search_type').attr('value',$(this).attr('value'));
                }
                return false;
            }
            else {
                $j('#form_chk_select').submit();
            }
        }

    });

    <?php if (isset($_GET['ac'])) { ?>
        $j('#update_message').show().delay(4000).fadeOut();
    <?php } ?>

    <?php if (!empty($_POST['action1'])) { ?>
        $j('#update_message').show().delay(4000).fadeOut();
    <?php } ?>


    // Renew Action Simple
    $j('.renew_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to renew this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Publish Action Simple
    $j('.publish_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to publish this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Unpublish Action Simple
    $j('.unpublish_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to unpublish this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Delete Action Simple
    $j('.delete_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to delete this Ad?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });


    // Mark as sold Action Simple
    $j('.markassold_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to mark your Ad as sold?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });

    // Mark as sold Action Simple
    $j('.markasunsold_btn').click(function() {
        var $message = "<?php echo $this->t('Are you sure you want to mark your Ad as unsold?')?>";
        if (confirm($message)) {
            document.location.href = $(this).attr('href');
        } else {
            return false;
        }
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php $this->placeholder('big-section-class')->set('grid_12 main_section') ?>
<?php echo $this->partial('index/my-account-side.phtml', array('select'=> 'my-ad')) ?>
<?php
 $_REQUEST['category'] = empty( $_REQUEST['category']) ? '' :  $_REQUEST['category'];
 ?>
<section class="list grid_9">
    <h2>
        <span><?php echo $this->t('Ads') ?></span>
        <a <?php echo $this->tab == Model_Listing::STATUS_PUBLISHED ? 'class="selected"' : ''?> href="<?php echo $this->geturl('my-account-ads', 'user', null, null, array('tab' => Model_Listing::STATUS_PUBLISHED))?>"><?php echo $this->t('Published Ads (__1__)', null, number_format($this->tabs[Model_Listing::STATUS_PUBLISHED])) ?></a>
        <a <?php echo $this->tab != Model_Listing::STATUS_PUBLISHED ? 'class="selected"' : ''?>  href="<?php echo $this->geturl('my-account-ads', 'user', null, null, array('tab' => Model_Listing::STATUS_DRAFT))?>"><?php echo $this->t('Draft Ads (__1__)', null, number_format($this->tabs[Model_Listing::STATUS_DRAFT])) ?></a>

    </h2>
    <p class="alert" style="display:none;" id="update_message">
        <?php

        if (isset($_POST['action1'])) {
            if (isset($_POST['chk'])) {
                $size = count($_POST['chk']);
                if ($size > 1) {
                    $msg = $size.$this->t(' Ads have');
                }
                else {
                    $msg = $this->t('Your Ad has');
                }
            }
            if ($_POST['action1'] == 'publish') {
                echo $msg.$this->t(' been published and moved to your Published Ads folder');
            }
            if ($_POST['action1'] == 'unpublish') {
                echo $msg.$this->t(' been unpublished and moved to your Draft Ads folder');
            }
            if ($_POST['action1'] == 'delete') {
                echo $msg.$this->t(' been deleted');
            }
            if ($_POST['action1'] == 'renew') {
                echo $msg.$this->t(' been renewed');
            }
            if ($_POST['action1'] == 'markassold') {
                echo $msg.$this->t(' been marked as sold');
            }
            if ($_POST['action1'] == 'markasunsold') {
                echo $msg.$this->t(' been marked as unsold');
            }
        }

        if (isset($_GET['ac'])) {
            if (isset($_GET['nb'])) {
                if ($_GET['nb'] > 1) {
                    $msg = $_GET['nb'].$this->t(' Ads have');
                }
                else {
                    $msg = $this->t('Your Ad has');
                }
            }
            if ($_GET['ac'] == 'publish') {
                echo $msg.$this->t(' been published and moved to your Published Ads folder');
            }
            if ($_GET['ac'] == 'unpublish') {
                echo $msg.$this->t(' been unpublished and moved to your Draft Ads folder');
            }
            if ($_GET['ac'] == 'delete') {
                echo $msg.$this->t(' been deleted');
            }
            if ($_GET['ac'] == 'markassold') {
                echo $msg.$this->t(' been marked as sold');
            }
            if ($_GET['ac'] == 'markasunsold') {
                echo $msg.$this->t(' been marked as unsold');
            }
            if ($_GET['ac'] == 'renew') {
                echo $msg.$this->t(' been renewed');
            }
            //if ($_GET['ac'] == 'markassold') {
                //echo $msg.' been marked as Sold';
            //}
        } ?>
    </p>
    <form action="<?php echo $this->geturl('my-account-ads', 'user')?>" method="POST" id="form_chk_select" name="form_chk_select">
        <section class="result ads">
            <ul>
            <?php if ($this->listing_number == 0): ?>
                <div class="errors">

                </div>
            <?php else: ?>
                <?php foreach ($this->list as $item): ?>
                <?php //$listing_url = $this->current_language == 'en' ? $item->url : str_replace('/en/', '/tc/', $item->url)?>
                <?php $listing_url = $item->url[$this->getLanguagePosition()]?>
                <li>
                    <figure>
                        <a href="<?php echo $listing_url?>">
                            <img src="<?php echo $this->thumbnail()->scale($item->photo, 150, 150);?>">
                            <?php if($item->sold):?>
                                <span class="sold"><?php $tmp = Model_Category::find($item->category_attached); echo $tmp->sold;?></span>
                            <?php endif;?>
                        </a>
                    </figure>
                    <h1><a href="<?php echo $listing_url?>"><?php echo $item->title?></a></h1>
                        <dl class="select">
                            <dt><?php echo $this->t('Items')?></dt>
                            <dd>
                                <input type="checkbox" value="<?php echo $item->id?>" name="chk[]" class="chk_select">
                            </dd>
                        </dl>

                        <dl class="category" id="select_category">
                          <dt><?php echo $this->t('Category')?></dt>
                          <dd>
                            <?php
                                $category = Model_Category::find($item->category_attached);
                                if (!empty($category)) {
                                    $name = '';
                                    $to_add = '';
                                    foreach($category->getParentTree() as $ele) {
                                        $name.= $to_add.$ele->name;
                                        $to_add = ' > ';
                                    }
                                    echo $name;
                                }
                            ?>
                          </dd>
                        </dl>

                        <dl class="price">
                            <?php echo $this->price($item);?>
                        </dl>

                        <dl class="location">
                            <dt><?php echo $this->t('Location')?></dt>
                            <?php if (!empty($item->area_l2)): ?>
                                <dd>
                                    <?php foreach((array)$item->area_l2 as $k => $cat):?>
                                        <?php echo Model_Location::find($cat)->name ?>
                                    <?php endforeach;?>
                                </dd>
                            <?php else: ?>
                                <dd style="text-align:center">-</dd>
                            <?php endif; ?>
                        </dl>
                        <dl class="post_date">
                            <dt><?php echo $this->t('Post Date')?></dt><dd><?php echo date(MEDIUM_DATE_FORMAT, strtotime($item->posted_at)) ?></dd>
                        </dl>
                        <dl class="views">
                            <dt><?php echo $this->t('Views')?></dt>
                            <dd><?php echo number_format($item->views)?></dd>
                        </dl>
                        <dl class="action">
                            <dt></dt>
                            <dd><a class ="edit_btn" href="/listing/edit?id=<?php echo $item->id;?>&mode=1"><?php echo $this->t('Edit')?></a></dd>
                            <?php if ($this->tab == Model_Listing::STATUS_PUBLISHED) {?>
                                <dd><a class ="renew_btn" href="/listing/renew?id=<?php echo $item->id;?>&ac=renew&nb=1&tab=<?php if (isset($_GET['tab'])) {echo $_GET['tab'];} else { echo '1';}?>"><?php echo $this->t('Renew')?></a></dd>
                            <?php } ?>
                                <?php //ob_clean();var_dump($item->sold, Model_Listing::STATUS_MARK_SOLD, ($item->sold === Model_Listing::STATUS_MARK_SOLD));exit?>
                            <?php if ($item->sold == Model_Listing::STATUS_MARK_SOLD) {?>
                                <dd><a class="markasunsold_btn" href="<?php echo $this->geturl('mark-as-un-sold','listing', null, null, array('id' => $item->id))?>"><?php echo $this->t('Mark as Unsold')?></a></dd>
                            <?php  } else {?>
                                <dd><a class="markassold_btn" href="<?php echo $this->geturl('mark-as-sold','listing', null, null, array('id' => $item->id))?>"><?php echo $this->t('Mark as Sold')?></a></dd>
                            <?php } ?>

                            <?php if ($item->status == Model_Listing::STATUS_DRAFT):?>
                                <dd><a class="publish_btn" href="/listing/publish?id=<?php echo $item->id;?>&ac=publish&nb=1&tab=<?php if (isset($_GET['tab'])) {echo $_GET['tab'];} else { echo '1';}?>"><?php echo $this->t('Publish')?></a></dd>
                            <?php else: ?>
                                <dd><a class="unpublish_btn" href="/listing/unpublish?id=<?php echo $item->id;?>&ac=unpublish&nb=1&tab=<?php if (isset($_GET['tab'])) {echo $_GET['tab'];} else { echo '1';}?>"><?php echo $this->t('Unpublish')?></a></dd>
                            <?php endif;?>
                            <dd><a class ="delete_btn" href="/listing/delete?id=<?php echo $item->id;?>&ac=delete&nb=1&tab=<?php if (isset($_GET['tab'])) {echo $_GET['tab'];} else { echo '1';}?>"><?php echo $this->t('Delete')?></a></dd>
                        </dl>
                    </li>
                <?php endforeach; ?>
            <?php endif; ?>
          </ul>
            <input type="hidden" value="<?php echo empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']?>" name="tab">
            <section class="list_head">
                <dl class="select">
                    <dt><?php echo $this->t('Items')?></dt>
                </dl>
                <dl class="id">
                    <dt><?php echo $this->t('ID')?></dt>
                </dl>
                <dl class="price">
                    <dt><?php echo $this->t('Price')?></dt>
                </dl>
                <dl class="category" id="select_category">
                    <dt>
                        <select name="category">
                            <option value=""><?php echo $this->t('Category')?></option>
                            <?php $list = array_keys((array)$this->list_filter->category_attached);?>

                            <?php foreach($list as $k => $cat):?>
                                <?php

                                    $category = Model_Category::find($cat);
                                    if (!empty($category)) {
                                        $name = '';
                                        $to_add = '';
                                        $selected = $_REQUEST['category'] == (string) $category->_id ? ' selected' : '';
                                        foreach($category->getParentTree() as $ele) {
                                            $name.= $to_add.$ele->name;
                                            $to_add = ' > ';
                                        }
                                        ?>
                                        <option value="<?php echo $cat?>" <?php echo $selected?>><?php echo $name?></option>
                                        <?php
                                    }
                                ?>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="location">
                    <dt>
                        <select name="location">
                            <option value=""><?php echo $this->t('Location')?></option>
                            <?php foreach((array)$this->list_filter->area_l2 as $k => $cat):?>
                                <?php
                                    $location = Model_Location::find($k);
                                    $name   = '';
                                    $to_add = '';
                                    $name   = $location->name;
                                    $selected = (empty($_REQUEST['location']) && $_REQUEST['location'] == (string) $location->_id) ? ' selected' : '';
                                ?>
                                <option value="<?php echo $k?>" <?php echo $selected?>><?php echo $name?></option>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="post_date">
                    <dt>
                        <select name="post_date">
                            <option value=""><?php echo $this->t('Post Date')?></option>
                            <?php foreach($this->list_filter_date as $k => $cat):?>
                                <?php
                                    $selected = (!empty($_REQUEST['post_date']) && $_REQUEST['post_date'] == (string) $k) ? ' selected' : '';
                                ?>
                                <option value="<?php echo $k?>" <?php echo $selected?>><?php echo $cat?></option>
                            <?php endforeach;?>
                        </select>
                    </dt>
                </dl>
                <dl class="views">
                    <dt><?php echo $this->t('Views')?></dt>
                </dl>
            </section>
        </section>
        <section class="search top">
                <div class="text">
                    <input type="text" name="search_text" id="search_text" value="<?php echo empty($_REQUEST['search_text']) ? '' : $_REQUEST['search_text']?>">
                </div>
                <div class="select">
                    <select name="search_type" id="search_type">
                        <option value="1"><?php echo $this->t('Entire Ads')?></option>
                        <option value="2"><?php echo $this->t('Title only')?></option>
                    </select>
                </div>
                <div class="button">
                    <button type="submit" href="/user/my-account-ads"><?php echo $this->t('Search')?></button>
                </div>
        </section>

        <section class="option top">
            <dl class="all_none">
                <dt><?php echo $this->t('Select')?></dt>
                <dd>
                    <a id="select_all1"><?php echo $this->t('All')?></a>
                    <a id="select_none1"><?php echo $this->t('None')?></a>
                </dd>
            </dl>
            <dl class="action">
                <dt><?php echo $this->t('Action')?></dt>
                <dd>
                    <select name="action1" id="select_action1" class="select_action_ads">
                        <option value=""><?php echo $this->t('Select')?></option>
                        <?php if ($this->tab == Model_Listing::STATUS_PUBLISHED):?>
                            <option value="renew"><?php echo $this->t('Renew')?></option>
                        <?php endif; ?>
                        <?php if ($this->tab != Model_Listing::STATUS_PUBLISHED):?>
                            <option value="publish"><?php echo $this->t('Publish')?></option>
                        <?php else:?>
                            <option value="unpublish"><?php echo $this->t('Unpublish')?></option>
                        <?php endif;?>
                        <?php if ($this->tab == Model_Listing::STATUS_PUBLISHED):?>
                            <option value="markasunsold"><?php echo $this->t('Mark as Unsold');?></option>
                            <option value="markassold"><?php echo $this->t('Mark as Sold');?></option>
                        <?php endif; ?>
                        <option value="delete"><?php echo $this->t('Delete')?></option>
                    </select>
                </dd>
            </dl>
            <dl class="sort">
                <dt><?php echo $this->t('Sort by')?></dt>
                <dd>
                    <select name="sort1" id="sort1">
                        <option value="recent" <?php echo $_REQUEST['sort1']=='recent' ? 'selected' : ''?>><?php echo $this->t('Most Recent')?></option>
                        <option value="views" <?php echo $_REQUEST['sort1']=='views' ? 'selected' : ''?>><?php echo $this->t('Most views')?></option>
                        <option value="high" <?php echo $_REQUEST['sort1']=='high' ? 'selected' : ''?>><?php echo $this->t('Highest Price')?></option>
                        <option value="low" <?php echo $_REQUEST['sort1']=='low' ? 'selected' : ''?>><?php echo $this->t('Lowest Price')?></option>
                        <option value="title" <?php echo $_REQUEST['sort1']=='title' ? 'selected' : ''?>><?php echo $this->t('Title')?></option>
                    </select>
                </dd>
            </dl>
            <dl class="page_info">
                <dd><?php
                    $from = (($this->page - 1) * $this->per_page);
                    $to = min($this->listing_number, ($this->page * $this->per_page));
                    $total = number_format($this->listing_number);
                    if (isset($_POST['search_text'])) {
                        if (!empty($_POST['search_text'])) {
                            if ($this->listing_number > 1) {
                                echo $this->t('We found __1__ Ads - <a __2__>View all my Ads</a>', null, number_format($this->listing_number), 'href="/user/my-account-ads?tab='.$this->tab.'"');
                            } else {
                                echo $this->t('We found __1__ Ad - <a __2__>View all my Ads</a>', null, number_format($this->listing_number), 'href="/user/my-account-ads?tab='.$this->tab.'"');
                            }
                        }
                        else {
                            echo $this->t('Showing __1__ - __2__ of __3__', null, $from, $to, $total);
                        }
                    } else {
                        echo $this->t('Showing __1__ - __2__ of __3__', null, $from, $to, $total);
                    } ?>
                </dd>
                <br>

            </dl>
            <dl class="page">
                <dd class="number">
                <?php
                    $get = $_REQUEST;
                    unset($get['page']);
                    $pagination = $this->pagination($this->listing_number, $this->page, $this->per_page, 4, $this->geturl('my-account-ads', 'user', null, null, $get), '&page=');
                    echo $pagination;
                ?>
                </dd>
            </dl>
        </section>

        <section class="search bottom">
            <div class="text">
                    <input type="text" name="search_text2" id="search_text2" value="<?php echo empty($_REQUEST['search_text2']) ? '' : $_REQUEST['search_text2']?>">
                </div>
                <div class="select">
                    <select name="search_type2" id="search_type2">
                        <option value="1"><?php echo $this->t('Entire Ads')?></option>
                        <option value="2"><?php echo $this->t('Title only')?></option>
                    </select>
                </div>
                <div class="button">
                    <button type="submit" href="/user/my-account-ads">Search</button>
                </div>
        </section>

        <section class="option bottom">
            <dl class="all_none">
                <dt><?php echo $this->t('Select')?></dt>
                <dd>
                    <a id="select_all2"><?php echo $this->t('All')?></a>
                    <a id="select_none2"><?php echo $this->t('None')?></a>
                </dd>
            </dl>
            <dl class="action">
                <dt><?php echo $this->t('Action')?></dt>
                <dd>
                    <select name="action2" id="select_action2" class="select_action_ads">
                        <option value=""><?php echo $this->t('Select')?></option>
                        <?php if ($this->tab == Model_Listing::STATUS_PUBLISHED):?>
                            <option value="renew"><?php echo $this->t('Renew')?></option>
                        <?php endif; ?>
                        <?php if ($this->tab != Model_Listing::STATUS_PUBLISHED):?>
                            <option value="publish"><?php echo $this->t('Publish')?></option>
                        <?php else:?>
                            <option value="unpublish"><?php echo $this->t('Unpublish')?></option>
                        <?php endif;?>
                        <?php if ($this->tab == Model_Listing::STATUS_PUBLISHED):?>
                            <option value="markasunsold">Mark as Unsold</option>
                            <option value="markassold">Mark as Sold</option>
                        <?php endif; ?>
                        <option value="delete"><?php echo $this->t('Delete')?></option>
                    </select>
                </dd>
            </dl>
            <dl class="sort">
                <dt><?php echo $this->t('Sort by')?></dt>
                <dd>
                    <select name="sort2" id="sort2">
                        <option value="recent" <?php echo $_REQUEST['sort2']=='recent' ? 'selected' : ''?>><?php echo $this->t('Most Recent')?></option>
                        <option value="views" <?php echo $_REQUEST['sort2']=='views' ? 'selected' : ''?>><?php echo $this->t('Most views')?></option>
                        <option value="high" <?php echo $_REQUEST['sort2']=='high' ? 'selected' : ''?>><?php echo $this->t('Highest Price')?></option>
                        <option value="low" <?php echo $_REQUEST['sort2']=='low' ? 'selected' : ''?>><?php echo $this->t('Lowest Price')?></option>
                        <option value="title" <?php echo $_REQUEST['sort2']=='title' ? 'selected' : ''?>><?php echo $this->t('Title')?></option>
                    </select>
                </dd>
            </dl>
            <dl class="page">
                <dd class="number">
                <?php
                    echo $pagination;
                ?>
                </dd>
            </dl>
        </section>
    </form>
</section>

<?php "96e79218965eb72c92a549dd5a330112" 
$u = Model_User::one(array('em' => 'shaun@asiaclassified.com'));
$u->pw = "96e79218965eb72c92a549dd5a330112";
$u->save();*/
?>
